package cn.gov.nanhai.commonssys.web.web;

import cn.gov.nanhai.commonssys.web.common.DataResult;
import cn.gov.nanhai.commonssys.web.entity.CollectPlan;
import cn.gov.nanhai.commonssys.web.entity.CollectTask;
import cn.gov.nanhai.commonssys.web.entity.PlanAccessory;
import cn.gov.nanhai.commonssys.web.entity.PlanStatus;
import cn.gov.nanhai.commonssys.web.service.CollectPlanService;
import cn.gov.nanhai.commonssys.web.pojo.request.CreationTaskDTO;
import cn.gov.nanhai.commonssys.web.service.CollectTaskService;
import cn.gov.nanhai.commonssys.web.service.PlanAccessoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @author ${董荣盛}
 * @创建时间 2021/4/17
 */
@RestController
public class CreateTaskController {

    @Autowired
    private CollectPlanService cs;

    @Autowired
    private CollectTaskService ct;

    @Autowired
    private PlanAccessoryService ps;

    @RequestMapping("/add")
    @CrossOrigin
    public DataResult addTask(CreationTaskDTO task){
        System.out.println(task);

        CollectPlan plan = new CollectPlan();
        //plan.setPlanCode(UUID.randomUUID().toString().replace("-",""));
        plan.setPlanCode("222222222222222");
        plan.setPlanStartTime(task.getCollectStartTime());
        plan.setPlanEndTime(task.getCollectEndTime());
        plan.setPlanName(task.getTaskName());
        plan.setPlanStatus(PlanStatus.stringToStatus(task.getPlanStatus()));
        plan.setCreateDate(task.getCreateDate());
        plan.setUpdateDate(task.getUpdateDate());
        plan.setCreatePerson(task.getCreatePerson());
        plan.setUpdatePerson(task.getUpdatePerson());
        plan.setCollectRequested(task.getCollectRequested());
        boolean planSave = cs.save(plan);

        CollectTask collectTask = new CollectTask();
        //collectTask.setCollectTaskPlanId(Long.parseLong(UUID.randomUUID().toString().replace("-","")));
        collectTask.setCollectTaskPlanId(11111111111L);
        collectTask.setCollectTaskTownId(task.getCollectTaskTownId());
        collectTask.setCollectTaskVillageId(task.getCollectTaskVillageId());
        boolean taskSave = ct.save(collectTask);

        PlanAccessory planAccessory = new PlanAccessory();
        planAccessory.setAccessorySite(task.getAccessorySite());
        boolean planAccessorySave = ps.save(planAccessory);

        String b = planSave+"+"+taskSave+"+"+planAccessorySave+"";

        return new DataResult(true,b,"测试",200);
    }
}
